#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int n, k;
int arr[N];
int fun()
{
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int k = arr[i];
		while (k) {
			ans += k % 10;
			k /= 10;
		}
	}
	return ans;
}
int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &arr[i]);
	}
	int mi = 100;
	while (k--) {
		int idx = 0;
		int ma = -100;
		for (int i = 1; i <= n; i++) {
			int z = arr[i] % 10;
			if (z > ma) {
				ma = z;
				idx = i;
			}
		}
		arr[idx]--;
		mi = min(fun(), mi);
	}
	cout << mi << endl;
	return 0;
}